﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Web.manager
{
    public partial class modulerole : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(Request["roleid"]))
            {
                throw new Base.CustomException("缺少参数roleid");
            }

            Hashtable role = PhoneBook.Manage.SysRole.get(Request["roleid"]);
            if (role == null)
            {
                throw new Base.CustomException("参数roleid不正确");
            }

            if (!string.IsNullOrEmpty(Commons.StrUtil.FormatValue(role["groupid"])))
            {
                throw new Base.CustomException("无权限修改此角色");
            }

            SetDivePage(ref GridView1, ref GV);
            if (!IsPostBack)
            {
                QueryData();
            }
        }

        public override void QueryData()
        {
            DataSet ds = PhoneBook.Manage.sysModuleRole.get(Request["roleid"]);
            Commons.DataUtil.DataSort(ds, "systemid,pmodulename");
            //绑定数据集
            GVDataBind(ref GridView1, ref GV, ds);
        }



        protected void btn_save_Click(object sender, EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox cb_sel = row.FindControl("cb_sel") as CheckBox;
                if (cb_sel == null) continue;
                string moduleid = string.Empty;
                if (GridView1.DataKeys.Count > 0)
                {
                    moduleid = GridView1.DataKeys[row.RowIndex]["moduleid"].ToString();
                    if (cb_sel.Checked)
                        PhoneBook.Manage.sysModuleRole.add(moduleid, Request["roleid"]);
                    else
                        PhoneBook.Manage.sysModuleRole.del(moduleid, Request["roleid"]);
                }
            }

            Hashtable sysrole = PhoneBook.Manage.SysRole.get(Request["roleid"]);
            AddLog("修改了角色({0})权限，请进入角色权限管理查看", sysrole["rolename"]);
            Helper.ShowMessage(u_message, controls.UCMessageType.success, "保存成功");
            QueryData();
        }
    }
}